import axios from 'axios'

axios.defaults.maxBodyLength = 5 * 1024 * 1024;
axios.defaults.withCredentials = true;

const Axios = axios.create({
  // baseURL: "http://localhost:3000",
  baseURL: import.meta.env.VITE_APP_BASE_URL,
  timeout: 3000,
  headers: {
    "Content-Type": "application/json; charset=utf-8"
  },
  withCredentials: true
})

Axios.interceptors.request.use(
  (config) => {
    // console.log("请求拦截器");
    // let user = localStorage.getItem("token");
    // if (user) {
    //   let token = JSON.parse(user).token;
    //   config.headers.Authorization = token;
    //   // console.log(token);
    // }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

Axios.interceptors.request.use(
  (res) => {
    console.log('请求成功')
    return res
  },
  (error) => {
    console.log('请求失败了')
    return Promise.reject(new error('请求失败了'))
  }
)

export default Axios
